package com.training.java.core.homework02;

/**
 * LaptopArray program I created two similar programs for demonstrating array of
 * Laptop objects, the first one LaptopArrayDemo01 (i.e. this one) is for
 * creating 3 specific objects and storing in an array. The second one,
 * LaptopArrayDemo02, will demonstrate the same rigorously with arrays and for
 * loops.
 * 
 * @author Shovan
 * 
 */
public class LaptopArrayDemo01 {

	public static void main(String[] args) {

		// Instantiating 3 specific Laptop objects below.
		Laptop laptop1 = new Laptop(LaptopLocations.HOME);
		Laptop laptop2 = new Laptop(LaptopLocations.WORK);
		Laptop laptop3 = new Laptop(LaptopLocations.STARBUCKS);
		System.out.println("");

		// An array of 3 Laptop objects is created.
		Laptop[] laptops = new Laptop[3];

		// Manually storing the Laptop objects into it's array.
		laptops[0] = laptop1;
		laptops[1] = laptop2;
		laptops[1] = laptop3;

		// The array objects behave exactly like usual ones. This fact is
		// demonstrated below with one case, namely, by starting and stopping
		// the zeroth object of the array.
		System.out.println("Laptop objects laptops:");
		System.out.println("-----------------------");
		if (!laptops[0].isPowerOn()) {
			laptops[0].start();
		}
		System.out
				.println("I am going to work, so I'll be switching off laptop");
		if (laptops[0].isPowerOn()) {
			laptops[0].stop();
		}
		System.out.println("");

		// Another way to create & and initialize an array of 3 Laptop objects.
		Laptop[] laptops2 = { laptop1, laptop2, laptop3 };

		// Access them in similar manner.
		System.out.println("Laptop objects laptops2:");
		System.out.println("------------------------");

		if (!laptops2[0].isPowerOn()) {
			laptops2[0].start();
		}
		System.out
				.println("I am going to work, so I'll be switching off laptop");
		if (laptops2[0].isPowerOn()) {
			laptops2[0].stop();
		}
	}
}
